<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <meta content="width=device-width, initial-scale=1.0" name="viewport">

    <title>Wind</title>
    <meta content="" name="descriptison">
    <meta content="" name="keywords">

    <script src="https://fastly.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.min.js"></script>
    <script src="https://fastly.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>

    <!-- Favicons -->
    <link href="static/assets/img/favicon.png" rel="icon">
    <link href="static/assets/img/apple-touch-icon.png" rel="apple-touch-icon">

    <!-- Google Fonts -->
    <link href="https://fonts.googleapis.com/css?family=Open+Sans:300,300i,400,400i,600,600i,700,700i|Raleway:300,300i,400,400i,600,600i,700,700i,900"
          rel="stylesheet">

    <!-- Vendor CSS Files -->
    <link href="static/assets/vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link href="static/assets/vendor/icofont/icofont.min.css" rel="stylesheet">
    <link href="static/assets/vendor/boxicons/css/boxicons.min.css" rel="stylesheet">
    <link href="static/assets/vendor/animate.css/animate.min.css" rel="stylesheet">
    <link href="static/assets/vendor/venobox/venobox.css" rel="stylesheet">
    <link href="static/assets/vendor/aos/aos.css" rel="stylesheet">

    <!-- Template Main CSS File -->
    <link href="static/assets/css/style.css" rel="stylesheet">

</head>

<body>


<!-- ======= Header ======= -->
<header id="header">
    <div class="container">

        <div class="logo float-left">
            <h1 class="text-light"><a href="/index"><span>天气可视化系统的设计与实现</span></a></h1>
        </div>

        <nav class="nav-menu float-right d-none d-lg-block">
            <ul>
                <li><a href="/index">首页<i class="la la-angle-down"></i></a></li>

                <li class="drop-down"><a href="">可视化</a>
                    <ul>
                        <li><a href="/line">温度折线图</a></li>
                        <li><a href="/bar">天气柱状图</a></li>
                        <li class="active"><a href="/rose_pie">风力风向玫瑰图</a></li>
                        <li><a href="/pie">空气质量指数饼图</a></li>
                    </ul>
                </li>
                <li><a href="/data">数据展示</a></li>
                <li><a href="/weather">实时天气</a></li>
                <li><a href="/user_login">退出</a></li>
            </ul>
        </nav>

    </div>
</header><!-- End Header -->


<section id="about" class="about">
    <div class="">
        <!--  下拉框  -->
        <div class="container mt-5">
            <h3 class="text-center">风力风向查询</h3>
            <form id="query-form">
                <div class="form-row align-items-end">
                    <div class="form-group col-md-3">
                        <label for="city">城市:</label>
                        <select class="form-control" id="city">
                            <option value="潼南">潼南</option>
                            <option value="合川">合川</option>
                            <option value="渝北">渝北</option>
                            <option value="巴南">巴南</option>
                        </select>
                    </div>
                    <div class="form-group col-md-3">
                        <label for="year">年份:</label>
                        <select class="form-control" id="year">
                            <!-- Options from 2016 to 2023 -->
                            {% for year in range(2016, 2024) %}
                                <option value="{{ year }}">{{ year }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="form-group col-md-3">
                        <label for="month">月份:</label>
                        <select class="form-control" id="month">
                            <!-- Options from 1 to 12 -->
                            {% for month in range(1, 13) %}
                                <option value="{{ month }}">{{ month }}</option>
                            {% endfor %}
                        </select>
                    </div>
                    <div class="form-group col-md-3" style="text-align: center;">
                        <button type="submit" class="btn btn-primary">查询</button>
                    </div>
                </div>
            </form>
            <div id="wind-chart" style="width: 100%; height: 600px;" class="mt-5"></div>
        </div>
        <!--  Echarts  -->
        <script>
            $(document).ready(function () {
                $('#query-form').on('submit', function (event) {
                    event.preventDefault(); // 阻止表单默认提交

                    // 获取用户选择的城市、年份和月份
                    const city = $('#city').val();
                    const year = $('#year').val();
                    const month = $('#month').val();

                    // 发起AJAX请求
                    $.get(`/get_wind_data?city=${city}&year=${year}&month=${month}`, function (data) {
                        if (data.error) {
                            alert('获取数据失败: ' + data.error);
                            return;
                        }

                        // 处理返回的数据
                        const windData = data.wind_data;
                        const categories = windData.map(item => item.name);
                        const values = windData.map(item => item.value);

                        // 初始化ECharts实例
                        const chart = echarts.init(document.getElementById('wind-chart'));

                        // 配置图表
                        const option = {
                            title: {
                                text: data.title,
                                subtext: '风力风向分布',
                                left: 'center'
                            },
                            tooltip: {
                                trigger: 'item',
                                formatter: '{a} <br/>{b}: {c} ({d}%)'
                            },
                            legend: {
                                orient: 'vertical',
                                left: 'left',
                                data: categories
                            },
                            series: [
                                {
                                    name: '风力风向',
                                    type: 'pie',
                                    radius: '50%',
                                    {#center: ['50%', '60%'],#}
                                    roseType: 'radius',
                                    data: categories.map((category, index) => ({
                                        value: values[index],
                                        name: category
                                    })),
                                    emphasis: {
                                        itemStyle: {
                                            shadowBlur: 10,
                                            shadowOffsetX: 0,
                                            shadowColor: 'rgba(0, 0, 0, 0.5)'
                                        }
                                    }
                                }
                            ]
                        };

                        // 使用刚指定的配置项和数据显示图表
                        chart.setOption(option);
                    }).fail(function () {
                        alert('请求失败');
                    });
                });
            });
        </script>
    </div>
</section>

<footer id="footer">
    <div class="container">
      <div class="copyright">Copyright &copy; 2021.数据科学与大数据技术.<a target="_blank" href="#">天气可视化系统</a></div>
      <div class="credits"></div>
    </div>
</footer>


<a href="#" class="back-to-top"><i class="icofont-simple-up"></i></a>

<!-- Vendor JS Files -->
<script src="static/assets/vendor/jquery/jquery.min.js"></script>
<script src="static/assets/vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<script src="static/assets/vendor/jquery.easing/jquery.easing.min.js"></script>
<script src="static/assets/vendor/jquery-sticky/jquery.sticky.js"></script>
<script src="static/assets/vendor/venobox/venobox.min.js"></script>
<script src="static/assets/vendor/waypoints/jquery.waypoints.min.js"></script>
<script src="static/assets/vendor/counterup/counterup.min.js"></script>
<script src="static/assets/vendor/isotope-layout/isotope.pkgd.min.js"></script>
<script src="static/assets/vendor/aos/aos.js"></script>

<!-- Template Main JS File -->
<script src="static/assets/js/main.js"></script>


</body>

</html>